package com.gmics.unifiq.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gmics.android.R;
import com.gmics.unifiq.controller.EntityController;
import com.gmics.unifiq.entity.OpenEvent;

public class HomeAdapter extends BaseAdapter {
	private Context context;
	private ArrayList<OpenEvent> oeArr;
	// private final Integer[] imgID = {R.drawable.blue_square,
	// R.drawable.red_square, R.drawable.green_square, R.drawable.orange_square,
	// R.drawable.blue_square, R.drawable.red_square, R.drawable.green_square,
	// R.drawable.orange_square};
	public final static int[] imgArr = { R.drawable.blue_square,
		R.drawable.red_square, R.drawable.green_square, R.drawable.orange_square};

	public static int[] getImageArr() {
		return imgArr;
	}

	public HomeAdapter(Context context, ArrayList<OpenEvent> oeArr) {
		this.context = context;
		this.oeArr = oeArr;
	}

	@Override
	public int getCount() {
		return oeArr.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		TextView tv;
		if (convertView == null) {
			tv = new TextView(context);
			tv.setGravity(Gravity.CENTER);
			tv.setPadding(40, 30, 50, 30);

		} else {
			tv = (TextView) convertView;
		}

		if (position < imgArr.length){
			tv.setBackgroundResource(imgArr[position]);
		}
		else{
			int pos = (position + 1) % imgArr.length;
			tv.setBackgroundResource(imgArr[pos - 1]);
		}
		
		String summary = oeArr.get(position).getName()
				+ " @ "
				+ oeArr.get(position).getLocation()
				+ "\n\n"
				+ EntityController.convertDateTimeToString(oeArr.get(position)
						.getDateTime());

		tv.setText(summary);
		return tv;

	}
}